package cn.xinfei.xdecision.common.model.decisionflow;

import cn.xinfei.xdecision.common.model.enginex.po.EngineNode;
import cn.xinfei.xdecision.common.utils.util.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * Created by maying on 2023/03/05.
 **/
@Data
public class NodeSaveReqVo {

    @ApiModelProperty(value = "引擎编码", required = true, example = "jcl_001")
    @NotEmpty(message = "引擎编码不能为空")
    private String engineCode;

    @ApiModelProperty(value = "版本id", required = true, example = "1024")
    @NotNull(message = "版本id不能为空")
    private Long versionId;

    @ApiModelProperty(value = "节点类型", required = true, example = "start")
    @NotNull(message = "节点类型不能为空")
//	@InEnum(value = NodeTypeEnum.class, message = "节点类型必须是 {value}")
    private String nodeType;

    @ApiModelProperty(value = "节点名称", example = "规则集")
    @NotEmpty(message = "节点名称不能为空")
    private String nodeName;

    @ApiModelProperty(value = "节点顺序", example = "1")
    @NotNull(message = "节点顺序不能为空")
    private Integer nodeOrder;

    @ApiModelProperty(value = "节点编码", example = "jcl_20230415000006_9")
    private String nodeCode;

    @ApiModelProperty(value = "节点横坐标")
    @NotNull(message = "节点横坐标不能为空")
    private Double nodeX;

    @ApiModelProperty(value = "节点纵坐标")
    @NotNull(message = "节点纵坐标不能为空")
    private Double nodeY;

    @ApiModelProperty(value = "节点id")
    private Long nodeId;

    public EngineNode coverToEngineNode() {
        EngineNode engineNode =  EngineNode.builder()
				.nodeCode(nodeCode)
                .nodeName(nodeName)
                .nodeOrder(nodeOrder)
                .nodeType(nodeType)
                .nodeX(nodeX)
                .nodeY(nodeY)
                .versionId(versionId)
                .build();

        if(StringUtil.isBlank(engineNode.getNodeCode())){
        	engineNode.setNodeCode(engineCode + "_" + nodeOrder);
		}
		return engineNode;
    }

}
